import java.awt.*;
import javax.swing.*;
import java.lang.Thread;
public class window{

	Frame f = new Frame("maze");
	Panel p = new Panel();
	JButton[][] btn;
	private int size;

	public window(int Maze_Size)throws Exception{
		size = Maze_Size;
		btn = new JButton[Maze_Size][Maze_Size];
		p.setLayout(null);
		p.setBounds(30,30,400,400);
		init();
		f.add(p);
		f.pack();
		//f.setBounds(30,30,250,120);
		f.setVisible(true);
	}
	private void init()throws Exception{
		int ch;
		for(int i=0;i<size;i++){
			for(int j=0;j<size;j++){
				ch = setImg(i,j);
				btn[i][j] = new JButton();
				if(ch == 0) btn[i][j].setIcon(new ImageIcon("img/qiang.png"));
				else btn[i][j].setIcon(new ImageIcon("img/cao.png"));
				btn[i][j].setBounds(j*40,i*40,40,40);
				p.add(btn[i][j]);
			}
		}
	}
	private int setImg(int x,int y)throws Exception{
		maze m = new maze();
		if(m.maze[x][y]=='#') return 0;
		else return 1;
	}

	public void start(maze m)throws Exception{
		Thread sleep = new Thread();
		int x,y,px=-1,py=-1;
		for(int i=0;i<m.top;i++){
			if(px!=-1 && py!=-1) btn[px][py].setIcon(new ImageIcon("img/cao.png"));
			x = m.s.inn[i][0];
			y = m.s.inn[i][1];
			btn[x][y].setIcon(new ImageIcon("img/ren.png"));
			sleep.sleep(600);
			//System.out.println(x+","+y);
			px = x;
			py = y;
		}
	}
	public static void main(String[] args)throws Exception{
		maze m = new maze();
		m.runMaze();
		System.out.println("is:"+m.top);
		window w = new window(10);
		w.start(m);
	}
}